package com.hzhr.iot.log.convertor;

import com.hzhr.iot.log.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.log.model.log.LogModel;
import com.hzhr.iot.log.model.log.LogPostModel;
import com.hzhr.iot.log.model.log.LogPutModel;
import com.hzhr.iot.log.entity.LogEntity;
import com.hzhr.iot.log.entity.ext.LogEntityExt;
import com.hzhr.iot.log.entity.LogEntityWithBLOBs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.log.queryModel.custom.LogCustomQueryModel;

@Component
public class LogConvertor {

    public LogEntity postModel2entity(LogPostModel in) {
        //未转换字段: createTime updateTime id appCode 
        if (in == null) return null;
        LogEntity result = new LogEntity();

        result.setTransactionId(HzhrTypeUtil.string2string(in.getTransactionId()));
        result.setTransactionType(HzhrTypeUtil.string2string(in.getTransactionType()));
        result.setExistException(HzhrTypeUtil.string2string(in.getExistException()));
        result.setServiceName(HzhrTypeUtil.string2string(in.getServiceName()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setHttpMethod(HzhrTypeUtil.string2string(in.getHttpMethod()));
        result.setHttpRespCode(HzhrTypeUtil.integer2integer(in.getHttpRespCode()));
        result.setUserId(HzhrTypeUtil.integer2integer(in.getUserId()));
        result.setUserName(HzhrTypeUtil.string2string(in.getUserName()));
        result.setUserCode(HzhrTypeUtil.string2string(in.getUserCode()));
        return result;
    }
    public List<LogEntity> postModelList2entityList(List<LogPostModel> in) {
        if (in == null) return null;
        List<LogEntity> result = new ArrayList<>();
        for (LogPostModel item : in) {
            result.add(postModel2entity(item));
        }
        return result;
    }
    public LogEntityWithBLOBs postModel2withBLOBs(LogPostModel in) {
        //未转换字段: createTime updateTime id appCode 
        if (in == null) return null;
        LogEntityWithBLOBs result = new LogEntityWithBLOBs();

        result.setTransactionId(HzhrTypeUtil.string2string(in.getTransactionId()));
        result.setTransactionType(HzhrTypeUtil.string2string(in.getTransactionType()));
        result.setExistException(HzhrTypeUtil.string2string(in.getExistException()));
        result.setExceptionInfo(HzhrTypeUtil.string2string(in.getExceptionInfo()));
        result.setServiceName(HzhrTypeUtil.string2string(in.getServiceName()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setHttpMethod(HzhrTypeUtil.string2string(in.getHttpMethod()));
        result.setHttpReqBody(HzhrTypeUtil.string2string(in.getHttpReqBody()));
        result.setHttpRespCode(HzhrTypeUtil.integer2integer(in.getHttpRespCode()));
        result.setHttpRespBody(HzhrTypeUtil.string2string(in.getHttpRespBody()));
        result.setUserId(HzhrTypeUtil.integer2integer(in.getUserId()));
        result.setUserName(HzhrTypeUtil.string2string(in.getUserName()));
        result.setUserCode(HzhrTypeUtil.string2string(in.getUserCode()));
        return result;
    }
    public List<LogEntityWithBLOBs> postModelList2withBLOBsList(List<LogPostModel> in) {
        if (in == null) return null;
        List<LogEntityWithBLOBs> result = new ArrayList<>();
        for (LogPostModel item : in) {
            result.add(postModel2withBLOBs(item));
        }
        return result;
    }
    public void putModel2entity(LogEntity result, LogPutModel in) {
        //未转换字段: createTime updateTime appCode 
        if (result == null) return;
        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTransactionId(HzhrTypeUtil.string2string(in.getTransactionId()));
        result.setTransactionType(HzhrTypeUtil.string2string(in.getTransactionType()));
        result.setExistException(HzhrTypeUtil.string2string(in.getExistException()));
        result.setServiceName(HzhrTypeUtil.string2string(in.getServiceName()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setHttpMethod(HzhrTypeUtil.string2string(in.getHttpMethod()));
        result.setHttpRespCode(HzhrTypeUtil.integer2integer(in.getHttpRespCode()));
        result.setUserId(HzhrTypeUtil.integer2integer(in.getUserId()));
        result.setUserName(HzhrTypeUtil.string2string(in.getUserName()));
        result.setUserCode(HzhrTypeUtil.string2string(in.getUserCode()));
    }
    public void putModel2withBLOBs(LogEntityWithBLOBs result, LogPutModel in) {
        //未转换字段: createTime updateTime appCode 
        if (result == null) return;
        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTransactionId(HzhrTypeUtil.string2string(in.getTransactionId()));
        result.setTransactionType(HzhrTypeUtil.string2string(in.getTransactionType()));
        result.setExistException(HzhrTypeUtil.string2string(in.getExistException()));
        result.setExceptionInfo(HzhrTypeUtil.string2string(in.getExceptionInfo()));
        result.setServiceName(HzhrTypeUtil.string2string(in.getServiceName()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setHttpMethod(HzhrTypeUtil.string2string(in.getHttpMethod()));
        result.setHttpReqBody(HzhrTypeUtil.string2string(in.getHttpReqBody()));
        result.setHttpRespCode(HzhrTypeUtil.integer2integer(in.getHttpRespCode()));
        result.setHttpRespBody(HzhrTypeUtil.string2string(in.getHttpRespBody()));
        result.setUserId(HzhrTypeUtil.integer2integer(in.getUserId()));
        result.setUserName(HzhrTypeUtil.string2string(in.getUserName()));
        result.setUserCode(HzhrTypeUtil.string2string(in.getUserCode()));
    }

    public LogModel entity2model(LogEntity in) {
        //未转换字段: httpRespBody exceptionInfo httpReqBody 
        if (in == null) return null;
        LogModel result = new LogModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTransactionId(HzhrTypeUtil.string2string(in.getTransactionId()));
        result.setTransactionType(HzhrTypeUtil.string2string(in.getTransactionType()));
        result.setExistException(HzhrTypeUtil.string2string(in.getExistException()));
        result.setServiceName(HzhrTypeUtil.string2string(in.getServiceName()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setHttpMethod(HzhrTypeUtil.string2string(in.getHttpMethod()));
        result.setHttpRespCode(HzhrTypeUtil.integer2integer(in.getHttpRespCode()));
        result.setUserId(HzhrTypeUtil.integer2integer(in.getUserId()));
        result.setUserName(HzhrTypeUtil.string2string(in.getUserName()));
        result.setUserCode(HzhrTypeUtil.string2string(in.getUserCode()));
        result.setCreateTime(HzhrTypeUtil.date2long(in.getCreateTime()));
        result.setUpdateTime(HzhrTypeUtil.date2long(in.getUpdateTime()));
        return result;
    }
    public List<LogModel> entityList2modelList(List<LogEntity> in) {
        if (in == null) return null;
        List<LogModel> result = new ArrayList<>();
        for (LogEntity item : in) {
            result.add(entity2model(item));
        }
        return result;
    }
    public LogModel ext2model(LogEntityExt in) {
        //未转换字段: httpRespBody exceptionInfo httpReqBody 
        if (in == null) return null;
        LogModel result = new LogModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTransactionId(HzhrTypeUtil.string2string(in.getTransactionId()));
        result.setTransactionType(HzhrTypeUtil.string2string(in.getTransactionType()));
        result.setExistException(HzhrTypeUtil.string2string(in.getExistException()));
        result.setServiceName(HzhrTypeUtil.string2string(in.getServiceName()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setHttpMethod(HzhrTypeUtil.string2string(in.getHttpMethod()));
        result.setHttpRespCode(HzhrTypeUtil.integer2integer(in.getHttpRespCode()));
        result.setUserId(HzhrTypeUtil.integer2integer(in.getUserId()));
        result.setUserName(HzhrTypeUtil.string2string(in.getUserName()));
        result.setUserCode(HzhrTypeUtil.string2string(in.getUserCode()));
        result.setCreateTime(HzhrTypeUtil.date2long(in.getCreateTime()));
        result.setUpdateTime(HzhrTypeUtil.date2long(in.getUpdateTime()));
        return result;
    }
    public List<LogModel> extList2modelList(List<LogEntityExt> in) {
        if (in == null) return null;
        List<LogModel> result = new ArrayList<>();
        for (LogEntityExt item : in) {
            result.add(ext2model(item));
        }
        return result;
    }
    public LogModel withBLOBs2model(LogEntityWithBLOBs in) {
        //未转换字段: 
        if (in == null) return null;
        LogModel result = new LogModel();

        result.setExceptionInfo(HzhrTypeUtil.string2string(in.getExceptionInfo()));
        result.setHttpReqBody(HzhrTypeUtil.string2string(in.getHttpReqBody()));
        result.setHttpRespBody(HzhrTypeUtil.string2string(in.getHttpRespBody()));
        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTransactionId(HzhrTypeUtil.string2string(in.getTransactionId()));
        result.setTransactionType(HzhrTypeUtil.string2string(in.getTransactionType()));
        result.setExistException(HzhrTypeUtil.string2string(in.getExistException()));
        result.setServiceName(HzhrTypeUtil.string2string(in.getServiceName()));
        result.setUri(HzhrTypeUtil.string2string(in.getUri()));
        result.setHttpMethod(HzhrTypeUtil.string2string(in.getHttpMethod()));
        result.setHttpRespCode(HzhrTypeUtil.integer2integer(in.getHttpRespCode()));
        result.setUserId(HzhrTypeUtil.integer2integer(in.getUserId()));
        result.setUserName(HzhrTypeUtil.string2string(in.getUserName()));
        result.setUserCode(HzhrTypeUtil.string2string(in.getUserCode()));
        result.setCreateTime(HzhrTypeUtil.date2long(in.getCreateTime()));
        result.setUpdateTime(HzhrTypeUtil.date2long(in.getUpdateTime()));
        return result;
    }
    public List<LogModel> withBLOBsList2modelList(List<LogEntityWithBLOBs> in) {
        if (in == null) return null;
        List<LogModel> result = new ArrayList<>();
        for (LogEntityWithBLOBs item : in) {
            result.add(withBLOBs2model(item));
        }
        return result;
    }

    public LogCustomQueryModel query2queryModel(Map<String, Object> query) {
        LogCustomQueryModel queryModel = new LogCustomQueryModel();


        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

